﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class mobile_info : System.Web.UI.Page
{
    public string ind_id;
    public string email;

    protected void Page_Load(object sender, EventArgs e)
    {
        ind_id = this.Request.Params["ind"].ToString();  
        //根据ind_id在INFO_IND中查询到邮箱，存入email
        SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["wbkpt"].ConnectionString.ToString());
        sc.Open();
        SqlCommand com_get = new SqlCommand();
        com_get.Connection = sc;
        com_get.CommandText = "select IND_EMAIL from INFO_IND where IND_ID=@id";
        com_get.Parameters.AddWithValue("@id",ind_id);
        email = com_get.ExecuteScalar().ToString();
        
        label4.Text ="您的邮箱地址： "+ email;
        SqlCommand com_getcre = new SqlCommand("select IND_CREDITS from INFO_IND where IND_ID=@id1",sc);
        com_getcre.Parameters.AddWithValue("@id1",ind_id);
        label2.Text ="您拥有积分： "+com_getcre.ExecuteScalar().ToString();

        SqlCommand com_getname = new SqlCommand("select IND_NAME from INFO_IND where IND_ID=@id2",sc);
        com_getname.Parameters.AddWithValue("@id2", ind_id);
        label3.Text += com_getname.ExecuteScalar().ToString();
        sc.Close();
        Label1.Text="";

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Equals(email) == false&&TextBox1.Text!=""&&TextBox1.Text!=null)
        {
            //利用ind_id将邮箱地址更新回数据表
            SqlConnection sc1 = new SqlConnection(ConfigurationManager.ConnectionStrings["wbkpt"].ConnectionString.ToString());
            sc1.Open();
            SqlCommand com_update = new SqlCommand();
            com_update.Connection = sc1;
            com_update.CommandText = "update INFO_IND set IND_EMAIL=@email where IND_ID=@id";
            com_update.Parameters.AddWithValue("@email", TextBox1.Text);
            com_update.Parameters.AddWithValue("@id",ind_id);
            while (Application["sqllock"] == "lock")
            {//检测是否已经锁住
                System.Threading.Thread.Sleep(2000);
            }
            Application["sqllock"] = "lock";//上锁 
            if (com_update.ExecuteNonQuery() == 1)
            {
                Application["sqllock"] = "unlock";//解锁 
                sc1.Close();
                Page.RegisterStartupScript("ss", "<script>alert('修改邮箱成功！')</script>");
                return;
            }
            else
            {
                Application["sqllock"] = "unlock";//解锁 
                sc1.Close();
                Page.RegisterStartupScript("ss", "<script>alert('数据库异常，请重新提交修改！')</script>");
                return;
            }

        }
        else
        {
            Page.RegisterStartupScript("ss", "<script>alert('邮箱地址没有修改！')</script>");
            return;
        }
    }
}